package ysq.xyg.host.controller;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.host.model.po.HostItemMore;
import ysq.xyg.host.model.vo.HostItemMoreVo;
import ysq.xyg.host.service.HostItemMoreService;
import ysq.xyg.host.service.HostItemService;
import ysq.xyg.sys.model.po.SysUser;

import javax.servlet.http.HttpServletRequest;

/**
 * 房产-楼盘更多信息controller层
 *
 * @author congcong tao
 * @date 2019-12-11 15:18:19
 */
@RestController
public class HostItemMoreController extends BaseController {

    @Autowired
    private HostItemMoreService hostItemMoreService;
    @Autowired
    private HostItemService hostItemService;

    @RequestMapping(value = "/hostItemMore/getPage", method = RequestMethod.GET)
    public ModelAndView getPage(String itemId) {
        ModelAndView view = new ModelAndView("/host/hostItemMoreList");
        view.addObject("item", hostItemService.selectByPrimaryKey(itemId));
        return view;
    }

    /**
     * 分页查询
     *
     * @param hostItemMoreVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-12-11 15:18:19
     */
    @BaseLog(module = "房产", className = "楼盘更多信息",methods = "分页查询", businessType = BaseConstant.SYS_BUSINESS_TYPE_GET, operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostItemMore/page",method = RequestMethod.POST)
    public ReturnEntity page(HttpServletRequest request, HostItemMoreVo hostItemMoreVo, int pageSize, int pageNum){
        SysUser sysUser = acceptCurrentUser(request);
        hostItemMoreVo.setAccountId(sysUser.getAccountId());
        ReturnEntity returnEntity = hostItemMoreService.page(hostItemMoreVo, pageSize, pageNum);
        // 需要带出数据
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-12-11 15:18:19
     */
    @RequestMapping(value = "/hostItemMore/getEntity", method = RequestMethod.GET)
    public ModelAndView getEntity(String id, String itemId) {
        ModelAndView view = new ModelAndView("/host/hostItemMoreUpdateOrSave");
        if (StrUtil.isNotEmpty(id)) {
            HostItemMore hostItemMore = hostItemMoreService.selectByPrimaryKey(id);
            view.addObject("hostItemMore", hostItemMore);
            view.addObject("item", hostItemService.selectByPrimaryKey(hostItemMore.getItemId()));
        } else if (StrUtil.isNotEmpty(itemId)) {
            view.addObject("item", hostItemService.selectByPrimaryKey(itemId));
        }
        return view;
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-12-11 15:18:19
     */
    @BaseLog(module = "房产", className = "楼盘更多信息", methods = "删除", businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE, operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostItemMore/delete")
    public ReturnEntity delete(HttpServletRequest request, String id){
        return hostItemMoreService.delete(id, acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param hostItemMoreVo Vo对象
     * @author congcong tao
     * @date 2019-12-11 15:18:19
     */
    @BaseLog(module = "房产", className = "楼盘更多信息", methods = "添加或修改", businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE, operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostItemMore/addOrUpdate", method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request, HostItemMoreVo hostItemMoreVo){
        return hostItemMoreService.addOrUpdate(hostItemMoreVo, acceptCurrentUser(request));
    }

    @RequestMapping(value = "/hostItemMore/updateValue")
    public ReturnEntity updateValue(String id, String value){
        HostItemMore hostItemMore = hostItemMoreService.selectByPrimaryKey(id);
        hostItemMore.setValue(value);
        hostItemMoreService.updateByPrimaryKeySelective(hostItemMore);
        return new ReturnEntity();
    }
}